package smallChanges.Tokenization;

import smallChanges.statements.Statement;


public class TokenMappingEntry implements Comparable<TokenMappingEntry>{

    private SCToken leftToken;
    private SCToken rightToken;
    private Statement leftStatement;
    private Statement rightStatement;
    
    public enum TokenMappingStatus {VALID, PROBABLE, POSSIBLE, INVALID};
    
    private double normalizedEditDistance;
    private int crossings;
    
    private TokenMappingStatus status;

    public TokenMappingEntry (SCToken left, SCToken right,  int cross, TokenMappingStatus status,
    		Statement leftStmt, Statement rightStmt)
    {
        normalizedEditDistance = 1;
        this.leftToken = left;
        this.rightToken = right;
        if( left != null && right != null)
        {
            normalizedEditDistance = left.getNormalizedLevenshteinEditDistance(right);
        }
        crossings = cross;
        this.status = status;
        leftStatement = leftStmt;
        rightStatement = rightStmt;
    }
    
    public int compareTo(TokenMappingEntry other)
    {
        int result = 0;
        
        SCToken left,right;
        
        left =  this.getLeftToken();
        right = other.getLeftToken();
        
        result = left.getBeginColumn() - right.getBeginColumn(); 
        if( result == 0 )
        {
            result = left.getEndColumn() - right.getEndColumn(); 
        }
        return result;
    }
    
    public boolean equals(Object other)
    {
        TokenMappingEntry right = (TokenMappingEntry) other;
        
        return leftToken.getBeginLine() == right.getLeftToken().getBeginLine() && rightToken.getBeginLine() == right.getRightToken().getBeginLine() && leftToken.getImage().equals(rightToken.getImage()); 
    }
    
    public TokenMappingEntry()
    {
        normalizedEditDistance = -1.0;
        crossings = -1;
        status = TokenMappingStatus.INVALID;
        leftToken = null;
        rightToken = null;
    }

    public SCToken getLeftToken() {
        return leftToken;
    }

    public void setLeftToken(SCToken leftToken) {
        this.leftToken = leftToken;
    }

    public SCToken getRightToken() {
        return rightToken;
    }

    public void setRightToken(SCToken rightToken) {
        this.rightToken = rightToken;
    }

    public double getNormalizedEditDistance() {
        return normalizedEditDistance;
    }

    public void setNormalizedEditDistance(double normalizedEditDistance) {
        this.normalizedEditDistance = normalizedEditDistance;
    }

    public int getCrossings() {
        return crossings;
    }

    public void setCrossings(int crossings) {
        this.crossings = crossings;
    }

    public TokenMappingStatus getStatus() {
        return status;
    }

    public void setStatus(TokenMappingStatus status) {
        this.status = status;
    }

	public Statement getLeftStatement() {
		return leftStatement;
	}

	public void setLeftStatement(Statement leftStatement) {
		this.leftStatement = leftStatement;
	}

	public Statement getRightStatement() {
		return rightStatement;
	}

	public void setRightStatement(Statement rightStatement) {
		this.rightStatement = rightStatement;
	}

}
